//
// Created by Administrator on 2025/3/18.
//

#include "ui_elf_game_full_load_screen.h"



static void ui_elf_game_full_load_screen_event(lv_event_t *e){
    LOG_INFO_WRAPPER("start");
//    lv_group_send_data()
    lv_event_code_t event_code = lv_event_get_code(e);
    lv_obj_t *target = lv_event_get_target(e);
    lv_group_t *group = lv_group_get_default();
//    word_query_event_data_t * event_data = (word_query_event_data_t *)lv_event_get_user_data(e);
    if (event_code == LV_EVENT_KEY)
    {
        // 按键事件 获取按键值
        uint32_t lv_key = lv_event_get_key(e);
        switch (lv_key)
        {
            case LV_KEY_UP:
                LV_LOG_USER("=========== touched KeyUp");
                break;
            case LV_KEY_DOWN:
                LV_LOG_USER("============ touched KeyDown");
                break;
            case LV_KEY_LEFT:
                LV_LOG_USER("=========== touched KeyLeft");
//                lv_group_focus_prev(group);

                break;
            case LV_KEY_RIGHT:
                LV_LOG_USER("============ touched KeyRight");
//                lv_group_focus_next(group);

                break;
            case LV_KEY_ENTER:
                LV_LOG_USER("============ touched KeyEnter");
//                ui_word_query_enter_key(group,target,event_data);

                break;
            case LV_KEY_BACKSPACE:
                LV_LOG_USER("============ touched KeyBackspace");
//                ui_elf_game_full_load_screen_deinit(&elf_game_module);
                elf_game_module.screen->deinit_cb();
                elf_game_module.screen->current_page = ELF_GAME_NONE;
                break;
            case LV_KEY_ESC:
                LV_LOG_USER("============ touched ESC");

                break;
            default:
                break;
        }
    }
}

// 界面初始化
void ui_elf_game_full_load_screen_init(ui_elf_game_main_screen_t *screen){
    LOG_INFO_WRAPPER("start");
    if(screen->screen == NULL){
        if(screen->group == NULL){
            screen->group = ui_set_indev_group(indev_keypad);
        }
        screen->screen = ui_create_default_screen(lv_scr_act());
        lv_group_add_obj(screen->group, screen->screen);
        lv_obj_add_event_cb(screen->screen, ui_elf_game_full_load_screen_event, LV_EVENT_KEY, NULL);

        // 屏幕panel
        lv_obj_t *main_panel = ui_create_default_without_flex_panel(screen->screen);

        // image
        lv_obj_t *image = ui_create_default_image_by_src(main_panel, &elf_load_main_img);

    }
}

void ui_elf_game_full_load_screen_show(elf_game_module_t *module){
    LOG_INFO_WRAPPER("start");
    if(module){
        if(module->screen->screen == NULL){
            ui_elf_game_full_load_screen_init(module->screen);
        }
    }
    module->screen->current_page = ELF_GAME_FULL_LOAD_SCREEN;

    module->screen->deinit_cb = ui_elf_game_full_load_screen_deinit;

}
void ui_elf_game_full_load_screen_deinit(){
    LOG_INFO_WRAPPER("start");
    ui_screen_group_deinit_common(&(elf_game_module.screen->screen), &(elf_game_module.screen->group));
}